#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int N = 1e6+7;
int main()
{
	string a,b;
	cin>>a>>b;
	int l1,l2;
	l1=min(5-abs(a[1]-a[0]),abs(a[1]-a[0]));
	l2=min(5-abs(b[1]-b[0]),abs(b[1]-b[0]));
	if(l1==l2)cout<<"Yes";
	else cout<<"No";
	return 0;
}
